<?php

?>

<h2>
    <?php echo $this->translate("Question Poll ") ?>
</h2>
<?php if( count($this->navigation) ): ?>
<div class='tabs'>
        <?php
        // Render the menu
        //->setUlClass()
        echo $this->navigation()->menu()->setContainer($this->navigation)->render()
        ?>
</div>
<?php endif; ?>
<script type="text/javascript">
    var currentOrder = '<?php echo $this->order ?>';
    var currentOrderDirection = '<?php echo $this->order_direction ?>';
    var changeOrder = function(order, default_direction){
        // Just change direction
        if( order == currentOrder ) {
            $('order_direction').value = ( currentOrderDirection == 'ASC' ? 'DESC' : 'ASC' );
        } else {
            $('order').value = order;
            $('order_direction').value = default_direction;
        }
        $('filter_form').submit();
    }
    function multiDelete()
    {
      return confirm("<?php echo $this->translate("Are you sure you want to delete the selected polls?") ?>");
    }
    function selectAll()
    {
        
        var i;
        var multimodify_form = $('multimodify_form');
        var inputs = multimodify_form.elements;
        for (i = 1; i < inputs.length - 1; i++) {
            if (!inputs[i].disabled) {
                inputs[i].checked = inputs[0].checked;
            }
        }
    }
</script>
<div class='admin_search'>
    <div class="search">
        <form action="" method="post" class="global_form_box">
            <div>
                <label class="optional" tag="" for="title">Title</label>
                <input type="text" value="<?php echo $this->search_title;?>" id="title" name="title" size="50" />
            </div>
            <div>
                <label class="optional" tag="" for="owner">Owner</label>
                <input type="text" value="<?php echo $this->search_owner;?>" id="owner" name="owner" />
            </div>
            <div>
                <label class="optional" tag="" for="privacy">Share with</label>
                <select name="privacy">        
                    <option value="" <?php echo $this->search_privacy ? '' : 'selected="selected"';?>>All</option>
                    <option value="public" <?php echo $this->search_privacy == 'public' ? 'selected="selected"' : '';?>>Public</option>
                    <option value="friends" <?php echo $this->search_privacy == 'friends' ? 'selected="selected"' : '';?>>Friends Only</option>
                </select>
            </div>
            <div>
                <label class="optional" tag="" for="feature">Filter By</label>
                <select name="feature">
                    <option value="-1" <?php echo $this->search_feature == -1 ? 'selected="selected"' : '';?>>All</option>
                    <option value="1" <?php echo $this->search_feature == 1 ? 'selected="selected"' : '';?>>Feature</option>
                    <option value="0" <?php echo $this->search_feature == 0 ? 'selected="selected"' : '';?>>Not Feature</option>
                </select>
            </div>
            <div>
                <div class="buttons">
                <button type="submit">Search</button>
                </div>
            </div>
            <input type="hidden" name="search" value="1" />
        </form>
    </div>
</div>
<div class='admin_results'>
    <div style="margin: 10px 0px;">
        <?php $count = $this->paginator->getTotalItemCount() ?>
        <?php echo $this->translate(array("%s question found", "%s questions found", $count),
        $this->locale()->toNumber($count)) ?>
    </div>
    <div>
        <?php echo $this->paginationControl($this->paginator, null, null, array(
        'pageAsQuery' => true,
        'query' => $this->formValues,
        //'params' => $this->formValues,
        )); ?>
    </div>
</div>  
<div class="admin_table_form">
    <form id='multimodify_form' method="post" action="<?php echo $this->url(array('action'=>'multimodify'));?>" onSubmit="return multiDelete()">
    <table class='admin_table'>
        <thead>
            <tr>                
                <th class='admin_table_short'><input onclick='selectAll();' type='checkbox' class='checkbox' /></th>
                <th style='width: 3%;'><a href="javascript:void(0);" onclick="javascript:changeOrder('poll_id', 'ASC');"><?php echo $this->translate("ID") ?></a></th>
                <th style='width: 10%;'><a href="javascript:void(0);" onclick="javascript:changeOrder('user_id', 'ASC');"><?php echo $this->translate("Owner") ?></a></th>
                <th style='width: 57%;'><a href="javascript:void(0);" onclick="javascript:changeOrder('title', 'ASC');"><?php echo $this->translate("Title") ?></a></th>

                <th style='width: 15%;'><a href="javascript:void(0);" onclick="javascript:changeOrder('creation_date', 'ASC');"><?php echo $this->translate("Created Date") ?></a></th>

                <th style='width: 15%;' class='admin_table_options'><?php echo $this->translate("Options") ?></th>
            </tr>
        </thead>
        <tbody>
            <?php if( count($this->paginator) ): ?>
                <?php foreach( $this->paginator as $item ):
                    ?>
            <tr>
                <td><input type='checkbox' class='checkbox' name='qid[]' value='<?php echo $item->poll_id ?>' /></td>
                <td>
                    <a href="<?php echo $item->getHref();?>"><?php echo $item->poll_id; ?></a>
                </td>
                <td>
                    <a href="<?php echo $item->getHref(); ?>" >
                                <?php
                                $user = Engine_Api::_()->user()->getUser($item->user_id);
                                echo $this->htmlLink($user->getHref(), $user->getTitle());
                                ?>
                    </a>
                </td>
                <td> <a  href='<?php echo $this->url(array('controller' => 'poll', 'action' => 'show-all-options', 'poll' => $item->getIdentity()), 'poll_general',true);?>'><?php echo $item->title; ?></a></td>
                <td> <?php echo $this->timestamp($this->locale()->toDateTime( $item->creation_date));?></td>
                <td>  <?php $exist=false;?>
                    <a  href='<?php echo $this->url(array('controller' => 'poll', 'action' => 'show-all-options', 'poll' => $item->getIdentity()), 'poll_general',true);?>'>
                                <?php if($exist==true) echo '|';
        $exist=true;
        echo $this->translate("View") ?>
                    </a>

                    <a class='smoothbox' href='<?php echo $this->url(array('action' => 'delete', 'id' => $item->poll_id, 'user_id' => $item->user_id));?>'>
        <?php if($exist==true) echo '|';
        echo $this->translate(" Delete") ?>
                    </a>
                    
                    <a href='<?php echo $this->url(array('action' => 'feature', 'id' => $item->getIdentity()));?>'>
        <?php if($exist==true) echo '|';
        echo $item->feature ? $this->translate(" UnFeature") : $this->translate(' Feature'); ?>
                    </a>
                </td>
            </tr>
    <?php endforeach; ?>
<?php endif; ?>
        </tbody>
    </table>
    <br />
      <div class='buttons'>
    <button type='submit'><?php echo $this->translate("Delete Selected") ?></button>
  </div>
    </form>

</div>
